<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.example.jstl.User" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>JSTL使用</title>
</head>
<body>
<%
//准备数据
    List<User> users = new ArrayList<>();
    User u1 = new User("李白",28);
    users.add(u1);
    User u2 = new User("杜甫",18);
    users.add(u2);
    User u3 = new User("高适",32);
    users.add(u3);
    pageContext.setAttribute("userList",users);
    pageContext.setAttribute("lb",u1);
%>
<h2>表达式标签</h2>
c:out <br/>
<c:out value="${lb}" default="defaultValue"/>
<%-->等效于： ${lb} <%=pageContext.getAttribute("lb")%> --%>
<br/>
<%----%>
<c:out value="${lb.username}" >
    lb_username_test
</c:out>
<br/>
c:set<br/>
<c:set var="course" value="Java Web"/>
course的值: ${course}
<br/>
<c:set var="course2" >
    企业后端开发技术
</c:set>
course2的值: ${course2}
<br/>
<c:set target="${lb}" property="mobile" value="10086"/>
设置mobile之后的u1: ${lb}
<br/>
<c:set target="${lb}" property="password" >
    123456
</c:set>
设置password之后的u1:${lb}
c:remove :<br/>
<c:remove var="course2"/>
course2的值: ${course2}
<br/>
c:catch<br>

<c:catch var ="catchException">
    <% int x = 5/0;%>
</c:catch>

<c:if test = "${catchException != null}">
    <p>异常为 : ${catchException} <br />
        发生了异常: ${catchException.message}</p>
</c:if>

<h2> URL相关标签 </h2>
c:import<br/>
<c:import url="/MyDoGet">
    <c:param name="test" value="www.baidu.com"/>
</c:import>

c:url
<br/>
<c:url value="MyDoGet" var="myurl">
    <c:param name="test" value="www.qq.com"  />
</c:url>
<br/>
<a href="<c:out value="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/${myurl}"/>"> myurl </a>
<br/>

<h2> 流程控制标签 </h2>
c:if<br/>
c:if:
<br/>
<c:if test="${userList.size()>0}" var="listNotIsEmpty" />
userList是否有元素：${listNotIsEmpty}
<br/>


<c:if test="${not empty userList&&userList.size()>0}" var="b1" > <%--类似于：if(users!=null&&users.size()>0)--%>
    ${userList.get(0).username}
</c:if>
<br/>
c:choose :  <br/>
<%--<%  int a=1;--%>
<%--    switch (a){--%>
<%--        case 1:--%>
<%--            break;--%>
<%--        case 2:--%>
<%--            break;--%>
<%--        default:--%>
<%--            break;--%>
<%--    }--%>
<%--%>--%>

<%request.setAttribute("score", "75"); %>
<c:choose>
    <c:when test="${score>=90}">优秀</c:when>
    <c:when test="${score>=80&&score<90}">良好</c:when>
    <c:when test="${score>=70&&score<80}">中等</c:when>
    <c:when test="${score>=60&&score<70}">及格</c:when>
    <c:otherwise>不及格</c:otherwise>
</c:choose>
<h2>循环标签</h2>
c:forEach <br/>

<table  style="border:1px solid gray;">
    <th >
    <td>序号</td>
    <td>姓名</td>
    <td>年龄</td>
    </th>
    <c:forEach items="${userList}" var="item" varStatus="status">
        <tr >
            <td>${status.count}</td>
            <td>${item.username}</td>
            <td>${item.age}</td>
        </tr>
    </c:forEach>
</table>

c:forTokens：
<br/>
<%
    pageContext.setAttribute("msg", "这#是#一个#forTakons#示#例");
%>
<c:forTokens items="${msg}" delims="#" var="msg" begin="0" end="3" step="1">
    ${msg}<br>
</c:forTokens>







</body>
</html>
